package com.yun.util;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Author: fxy
 * @Date: 2022/01/25/17:34
 * @Description:
 */
@Data
public final class RestResult<T> {
    public static final String OPT_SUCCESS_STATUS = "complete";
    public static final String OPT_ERROR_STATUS = "error";
    @ApiModelProperty("api执行结果状态：成功:complete 失败: error")
    private String status;
    @ApiModelProperty("错误代码")
    private String errorCode;
    @ApiModelProperty("错误信息")
    private String errorMessage;
    @ApiModelProperty("分页查询的总记录数")
    private Long count;
    @ApiModelProperty("返回结果数据")
    private T resultData;

    public static <T> RestResult<T> success(T t) {
        return new RestResult("complete", (String) null, (String) null, 0L, t);
    }

    public static RestResult success() {
        return new RestResult("complete", (String) null, (String) null, 0L, (Object) null);
    }

    public static <T> RestResult<T> success(T t, Long count) {
        return new RestResult("complete", (String) null, (String) null, count, t);
    }

    public static <T> RestResult<T> successPage(T t, Long count) {
        return new RestResult("complete", (String) null, (String) null, count, t);
    }

    public static <T> RestResult<T> fail(String errorCode, String errorMessage) {
        return new RestResult("error", errorCode, errorMessage, 0L, (Object) null);
    }

    public static <T> RestResult<T> fail(String errorMessage) {
        return new RestResult("error", "001", errorMessage, 0L, (Object) null);
    }

    public static <T> RestResult<T> fail(EnumBase errorCode) {
        return fail(errorCode.getCode(), errorCode.getMessage());
    }

    public static <T> RestResult<T> failList(EnumBase errorCode, T t) {
        return new RestResult(errorCode.getCode(), errorCode.getMessage(), (String) null, 0L, t);
    }

    public RestResult() {
    }

    public RestResult(final String status, final String errorCode, final String errorMessage, final Long count, final T resultData) {
        this.status = status;
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
        this.count = count;
        this.resultData = resultData;
    }
}